package model

import (
	"github.com/gomodule/redigo/redis"
	"strconv"
	"tizhi_front/nspel"
)

type ConsultQuestion struct {
	Id          int64  `gorm:"AUTO_INCREMENT;primary_key;column:id"`
	Question    string `gorm:"column:question"`
	Answer      string `gorm:"column:answer"`
	Order       int64  `gorm:"column:order"`
	ConsultType int64  `gorm:"column:consult_type"`
}

func (c *ConsultQuestion) TableName() string {
	return "consult_question"
}

type ConsultQuestionE struct{}

func (c *ConsultQuestionE) SelectAllByConsultTypeOrderByOrderAsc(consultType int64) (consultQuestions []ConsultQuestion0, err error) {
	key := "consult_question0.consult_type:" + strconv.FormatInt(consultType, 10) + ".order.asc.all"
	err = nspel.RedisGetGob(key, &consultQuestions)
	if err == nil {
		return
	}
	if err != redis.ErrNil {
		nspel.Error(err)
	} else {
		err = nil
	}
	if err = nspel.GetOrm().Select([]string{"question", "answer"}).Where("consult_type = ?", consultType).Order("order").Find(&consultQuestions).Error; err != nil {
		return
	}
	nspel.RedisSetGob(key, consultQuestions)
	return
}

type ConsultQuestion0 struct {
	Question string `gorm:"column:question"`
	Answer   string `gorm:"column:answer"`
}

func (*ConsultQuestion0) TableName() string {
	return "consult_question"
}
